// 负责管理员登录、获取 token。
import request from './request'

const useMock = true

export function login(data) {
  if (useMock) {
    return new Promise((resolve) => {
      setTimeout(() => {
        if (data.username === 'admin' && data.password === '123456') {
          resolve({
            data: {
              code: 200,
              data: { token: 'mock-token' },
              msg: '登录成功'
            }
          })
        } else {
          resolve({
            data: {
              code: 401,
              msg: '账号或密码错误'
            }
          })
        }
      }, 500)
    })
  } else {
    return request.post('/auth/login', data)
  }
}
